<template>
  <div>
    <el-dialog title="自动挂账设置" :visible="dialogVisible" :close-on-click-modal="false" @close="close" width="850px">
      
      <div  style="margin-top: 15px;">
       <div class="tip">
        请选择店铺，选中的店铺在商家货源向你提号时，会自动挂账，订单转到交易中。
       </div>
        <div class="flex" style="background-color: #f3f3f3;padding: 10px;border-radius: 8px;">
            <el-input style="width: 200px;margin-right: 15px;" @change="search" v-model="queryParams.name" placeholder="请输入店铺名称" clearable size="small" />
            <el-button type="primary" @click="search">搜索</el-button>
        </div>
        <div class="zdgzchecks">
          <div style="margin: 7px 0;">
            <myCheckbox @change="isAllCheckChange" v-model="isAllCheck" :list="[{id:2,name:'全选'}]"></myCheckbox>
          </div>
          <div class="">
            <myCheckbox v-model="selectIds" :list="tenantListArr" :option="{valueKey: 'tenantId',labelKey: 'tenantName'}">
            </myCheckbox>
          </div>
        </div>
        <div style="height: 60px;"></div>
        <div class="center">
          <el-button @click="close()">取消</el-button>
          <el-button type="primary"  @click="submitForm()" >保存</el-button>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "",
  data() {
    return {
      dialogVisible: false,
      queryParams:{
        name:''
      },
      tenantListArr:[],
      selectIds:[],
      isAllCheck:[]
    };
  },
  computed: {
    tenantList() {
      return this.$store.getters.tenantList
    }
  },
  created() {
   
  },
  methods: {
    open(data) {
      this.isAllCheck = []
      this.selectIds = []
      this.queryParams.name = ''
      this.dialogVisible = true;
      this.tenantListArr = JSON.parse(JSON.stringify(this.tenantList))
      if(data){
        this.selectIds = data.split(',')
      }else{
        this.selectIds = []
      }
    },

      // 筛选店铺
    search() {
      if (this.queryParams.name) {
        this.tenantListArr = this.tenantList.filter((r) =>
          r.tenantName.includes(this.queryParams.name)
        );
      } else {
        this.tenantListArr = JSON.parse(JSON.stringify(this.tenantList));
      }
    },
     // 全选店铺
    isAllCheckChange(e) {
      this.selectIds = [];
      if (this.isAllCheck && this.isAllCheck.length) {
        this.tenantListArr.forEach((r) => {
          this.selectIds.push(r.tenantId);
        });
      } 
    },
    submitForm() {
      this.$emit('save',this.selectIds)
      this.close()
    },
   
    close() {
      this.dialogVisible = false;
    },
  },
};
</script>
<style scoped lang="scss">
.tip{
  color: #666;
  font-size: 15px;
  margin-bottom: 10px;
}
::v-deep .el-dialog__body{
  padding-top: 0 !important;
}
.zdgzchecks {
  padding-bottom: 20px;
  ::v-deep .checkbox-item {
    width: 150px;
    background: #ebeff8;
    border-radius: 4px;
    overflow: hidden;
    // padding-left: 8px;
    padding: 3px 5px;
    // margin-right: 10px;
    // margin-bottom: 10px;
  }
}
.center{
  width: 100%;
  padding: 15px;
  background: #fff;
  border-top: 1px solid #f1f1f1;
  position: absolute;
  bottom: 0;
  left: 0;
}
</style>
